﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class ODSTableDAL : DB
    {
        public ODSTableDAL(LoginInfo info)
        {
            base.loginInfo = info;
        } 
        public IList<ODSTable> GetList()
        {
            IList<ODSTable> result = new List<ODSTable>();
            try
            {
                HIDB.dbo conn =base.conn();
                DataTable dt = conn.StoredDataTable("[Working_db].[UP_GetODSTbList]");
                if (dt != null && dt.Rows.Count > 0)
                {
                    ODSTable model = null;
                    foreach (DataRow item in dt.Rows)
                    {
                        model = new ODSTable();
                        model.ODS_ID = item["ods_id"].ToString();
                        model.SchemaName = item["SchemaName"].ToString();
                        model.TableName = item["TableName"].ToString();
                        model.ChnName = item["ChnName"].ToString();

                        result.Add(model);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return result;
        }

        public string GetODSTbODSID(string schemaName, string tableName)
        {
            string result = string.Empty;
            try
            {
                HIDB.dbo conn =base.conn();
                SqlParameter[] sqlparams = new SqlParameter[] 
                { 
                      new SqlParameter("@SchemaName",schemaName)
                     ,new SqlParameter("@TableName",tableName)
                };
                DataTable dt = conn.StoredDataTable("[Working_db].[UP_GetODSTb_ODSID]", sqlparams);
                if (dt != null && dt.Rows.Count > 0)
                {
                    result = dt.Rows[0]["ods_id"].ToString();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return result;
        }
    }
}
